import { defineStore } from 'pinia'
import { ref } from 'vue'
import { userInfoService } from '@/api/user'

export const useUserStore = defineStore('user',() => {
  const token = ref('')
  const setToken = (newToken) => {
    token.value = newToken
  }
 const removeToken = () => {
    token.value = ''
  }
  //用户信息
  const userInfo = ref({})
  //获取用户信息
  const getUserInfo = async () => {
    const res = await userInfoService()
    userInfo.value = res.data.data
  }
  //删除用户信息
  const removeUserInfo = () => {
    userInfo.value = {}
  }

  return {
    token,
    setToken,
    userInfo,
    getUserInfo,
    removeToken,
    removeUserInfo,
  }
},
{
    persist: true // 持久化
  })
